package com.hxh.generater.vue.simple.gen;

import com.hxh.entity.Project;
import com.hxh.entity.po.ClassInfo;
import com.hxh.generater.common.simple.SimpleConfig;
import com.hxh.generater.springBoot.util.GetAllTables;
import com.hxh.generater.vue.genBase.InitVueProject;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 项目的创建流程，后续使用不同的模板生成代码时，需要继承本类 通过反射,动态调用
 */
@Slf4j
public class InitSimpleVueProject extends InitVueProject {

    /**
     * 初始化表的api和vue文件
     *
     * @param project
     * @param initExtendTable
     */
    @Override
    public void generationAllApiAndView(Project project, boolean initExtendTable) throws Exception {
        List<ClassInfo> classInfos;
        if (initExtendTable) {
            classInfos = GetAllTables.generationAllTableInfo(project);
        } else {
            classInfos = GetAllTables.generationAllTableInfoByList(project, SimpleConfig.simpleTemplateTableList);
        }
        for (ClassInfo classInfo : classInfos) {
            GenSimpleVue genSimpleVue = new GenSimpleVue();
            genSimpleVue.generationView(project, classInfo);
            genSimpleVue.generationApi(project, classInfo);
        }
    }

    @Override
    public void initSystemBase(Project project) throws Exception {
        GenerationVueSystemBase.generationBuildDir(project);
        GenerationVueSystemBase.generationConfigDir(project);
        GenerationVueSystemBase.generationSrcBaseDir(project);
        GenerationVueSystemBase.generationIndexHtml(project);
        GenerationVueSystemBase.generationPackageJson(project);
        GenerationVueSystemBase.generationOtherConfig(project);

        GenerationVueSystemBase.generationInitVueSysManagerPage(project);
        GenerationVueSystemBase.generationInitVueImportExportPage(project);

    }

    @Override
    public void initAddition(Project project) {

    }
}
